<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>配置</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <script src="./js/jquery-3.3.1.min.js"></script>
    <script src="./js/layui/layui.js"></script>

    <!-- <script src="./js/layui/layui.all.js"></script> -->
    <link rel="stylesheet" href="./js/layui/css/layui.css">
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .layui-form-label {
            width: 100px;
            padding-left: 0;
            padding-right: 0;
        }

        .layui-form {}

        .layui-form-item {
            max-width: 400px;
        }
    </style>
</head>

<body>
    <!-- 合并上报量:<input type="text" class="text"><br />
    上传的地址:<input type="text" class="text"><br />
    token位置:<select name="">
        <option value="cookie">cookie</option>
        <option value="localstorage">localstorage</option>
        <option value="sessionstorage ">sessionstorage </option>
    </select>
    token的键值名:<input type="text" class="text"><br />
    点击事件上传是否打开:<input type="checkbox" class="text"><br />
    页面进入上传是否打开:<input type="checkbox" class="text"><br />
    应用类型:<input type="text" class="text"><br /> -->
    <div style="height:50px;"></div>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">合并上报量</label>
            <div class="layui-input-block">
                <input type="text" name="val1" lay-verify="" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">上传的地址</label>
            <div class="layui-input-block">
                <input type="text" name="val2" lay-verify="" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">token位置</label>
            <div class="layui-input-block">
                <select name="selected" lay-filter="select">
                    <option value="cookie" selected="">cookie</option>
                    <option value="localstorage">localstorage</option>
                    <option value="sessionstorage ">sessionstorage</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">token的键值名</label>
            <div class="layui-input-block">
                <input type="text" name="val3" lay-verify="" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" pane="">
            <label class="layui-form-label">点击事件上传是否打开</label>
            <div class="layui-input-block">
                <input type="checkbox" name="clickup" lay-skin="primary" title="">
            </div>
        </div>
        <div class="layui-form-item" pane="">
            <label class="layui-form-label">页面进入上传是否打开</label>
            <div class="layui-input-block">
                <input type="checkbox" name="pageup" lay-skin="primary" title="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">应用类型</label>
            <div class="layui-input-block">
                <input type="text" name="val4" lay-verify="" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" id="buttonSubmit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
            </div>
        </div>
    </form>
    <script>
        function sendAjax(url, data, type, layer) {
            if (!type) {
                type = "GET";
            }
            $.ajax({
                type: type,
                url: url,
                data: data,
                contentType: 'application/json;charset=Utf-8',
                success: function (res) {
                    layer.msg(res.message);
                },
                dataType: "json",
                error: function (err) {
                    console.log(err)
                }
            });
        }
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form;
            var layer = layui.layer;

            //监听提交
            form.on('submit(demo1)', function (data) {
                // console.log(data.field)
                var obj = {
                    appType: data.field.val4,
                    submitCombineCount: data.field.val1,
                    submitUrl: data.field.val2,
                    tokenKey: data.field.val3,
                    tokenPosition: data.field.selected
                };
                if (data.field.pageup) {
                    obj.upPage = true
                } else {
                    obj.upPage = false
                }
                if (data.field.clickup) {
                    obj.clickOff = true
                } else {
                    obj.clickOff = false
                }

                // console.log(obj)
                sendAjax("/config/properties", JSON.stringify(obj), 'POST', layer)
                // layer.alert(JSON.stringify(data.field), {
                //     title: '最终的提交信息'
                // })

                return false;
            });



        });
    </script>

</body>

</html>